package com.baihan.angus.app.game.busshow.adps;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.baihan.angus.app.game.basic.BaseApplication;
import com.baihan.angus.app.game.basic.base.BaseAdp;
import com.baihan.angus.app.game.busshow.R;
import com.baihan.angus.app.game.common.bean.response.RoomResponse;
import com.baihan.angus.app.game.common.util.ImageLoader;
import com.qmuiteam.qmui.widget.QMUIRadiusImageView;

public class OnlookAreaAdp extends BaseAdp<RoomResponse.DataX.Data, OnlookAreaAdp.ViewHolder> {

    private OnItemClickListener mOnItemClickListener;

    @Override
    protected RecyclerView.ViewHolder createYourViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_onlook_area, parent, false);
        return new ViewHolder(view);
    }

    @Override
    protected void bindYourViewHolder(@NonNull ViewHolder holder, int position) {
        ViewHolder vh = (ViewHolder) holder;

        RoomResponse.DataX.Data data = getItem(position);

        vh.tvCurrentNo.setText(data.getJoin_num() + "");
        vh.tvTotal.setText(data.getScript().getNum() + "");
        vh.tvRoomOwner.setText(data.getUser().getNickname());

        if (null != data.getScript()) {
            vh.tvName.setText(data.getScript().getName());
            int difficulty = data.getScript().getDifficulty();
            if (difficulty == 0) {//0简单 1一般 2困难 3极难
                vh.tvLevel.setText("简单");
            } else if (difficulty == 1) {
                vh.tvLevel.setText("一般");
            } else if (difficulty == 2) {
                vh.tvLevel.setText("困难");
            } else if (difficulty == 3) {
                vh.tvLevel.setText("极难");
            }
            vh.tvDuration.setText(data.getScript().getScript_time() + "小时");
            vh.tvScore.setText(data.getScript().getScore());

            ImageLoader.loadImage(BaseApplication.getApplication().getApplicationContext(),
                    vh.ivPic, data.getScript().getCover(), R.mipmap.ic_test_bg, 4);
//            Glide.with(BaseApplication.getApplication().getApplicationContext())
//                    .load(data.getScript().getCover())
//                    .error(Glide.with(BaseApplication.getApplication().getApplicationContext())
//                    .load(R.mipmap.ic_test_bg))
//                    .into(vh.ivPic);
        }

        vh.llOnlookItem.setOnClickListener(v -> {
            mOnItemClickListener.onItemClick(position);
        });
    }

    @Override
    protected int getEmptyView() {
        return 0;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        QMUIRadiusImageView ivPic;
        TextView tvCurrentNo, tvTotal, tvName, tvRoomOwner, tvDate, tvTime, tvLevel, tvDuration, tvScore;
        LinearLayout llOnlook, llOnlookItem;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ivPic = itemView.findViewById(R.id.ivPic);
            tvCurrentNo = itemView.findViewById(R.id.tvCurrentNo);
            tvTotal = itemView.findViewById(R.id.tvTotal);
            tvName = itemView.findViewById(R.id.tvName);
            tvRoomOwner = itemView.findViewById(R.id.tvRoomOwner);
            tvDate = itemView.findViewById(R.id.tvDate);
            tvTime = itemView.findViewById(R.id.tvTime);
            tvLevel = itemView.findViewById(R.id.tvLevel);
            tvDuration = itemView.findViewById(R.id.tvDuration);
            tvScore = itemView.findViewById(R.id.tvScore);
            llOnlook = itemView.findViewById(R.id.llOnlook);
            llOnlookItem = itemView.findViewById(R.id.llOnlookItem);
        }
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {
        void onItemClick(int position);
    }
}
